<template>
  <div class="employees-container">
    <div class="app-container">
      <PageTOOLS>
        <template #left>
          <span>总记录数: {{ total }} 条</span>
        </template>
        <template #right>
          <el-button type="warning" size="small">excel导入</el-button>
          <el-button type="danger" size="small">excel导出</el-button>
          <el-button type="primary" size="small">新增员工</el-button>
        </template>
      </PageTOOLS>

      <el-card style="margin-top: 10px;">
        <el-table :data="employees" border>
          <el-table-column label="序号" type="index" />
          <el-table-column label="姓名" prop="username" />
          <el-table-column label="工号" prop="workNumber" />
          <el-table-column label="聘用形式" prop="formOfEmployment">
            <template v-slot="{row}">
              {{ formatEmployment(row.formOfEmployment) }}
            </template>
          </el-table-column>
          <el-table-column label="部门" prop="departmentName" />
          <el-table-column label="入职时间" prop="timeOfEntry" />
          <el-table-column label="操作" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">分配角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-row type="flex" justify="center" align="middle" style="height: 60px">
          <el-pagination layout="prev, pager, next" />
        </el-row>
      </el-card>
    </div>
  </div>
</template>
<script>
import { getEmployees } from '@/api/employees'
import empConstant from '@/constant/employees'
// import PageTOOLS from '@/components/PageTools'
const obj = {}
empConstant.hireType.forEach(item => {
  obj[item.id] = item.value
})
export default {
  // components: {
  //   PageTOOLS
  // },
  data() {
    return {
      q: {
        page: 1,
        pagesize: 10
      },
      total: 0,
      employees: []
    }
  },
  created() {
    this.loadEmployees()
  },
  methods: {
    async loadEmployees() {
      const res = await getEmployees(this.q).catch(e => console.log('获取信息失败原因：', e))
      this.employees = res.data.rows
      this.total = res.data.total
    },
    formatEmployment(code) {
      return obj[code]
    }
  }
}
</script>

